﻿@model SalesOrders
@section ToolBar{
    <div class="r-c-tool">
        <a href="javascript:location.reload();" class="l-btn fa fa-refresh"></a>
        <a href="javascript:void(0);" class="l-btn fa fa-search"></a>
    </div>
    <div class="r-c-list">
        @Html.ActionLink("出库单", "SellingOut", "SalesOrder", new { t = 0}, new { @class = "l-btn cur"})
    </div>
}
<div class="l-m-table">
    <table id="SalesOrders">
        <tr class="bgc3">
            <th>销售单号</th>
            <th>客户</th>
            <th>业务员</th>
            <th>收货地址</th>
            <th>收货人</th>
            <th>联系电话</th>
            <th>配送状态</th>
        </tr>
        @if (Model==null || Model.Items.Count <= 0) {
            <tr>
                <td colspan="11" class="t-c c0">暂无记录</td>
            </tr>
        }
        @foreach (SalesOrder c in Model.Items)
        {
            <tr class="pointer" id="@c.SalesOrderId">
                <td>@c.SalesOrderNo</td>
                <td>@c.Customer.CustomerName</td>
                <td>@(c.OrderEmployee == null? "" : c.OrderEmployee.EmployeeName)</td>
                <td>@c.Address</td>
                <td>@c.ContactName</td>
                <td>@c.Phone </td>
                <td>@CommonFun.GetDeliveryStatus(c.DeliveryStatusId,c.DeliveryTypeId)</td>
            </tr>
        }
        <tr class="l-page">
            <td colspan="11">
                @Html.Pager("Index", "SalesOrder", Model.TotalCount, (int)ViewBag.PageIndex, 8)
            </td>
        </tr>
    </table>
</div>
<div class="l-m-table l-margin-t10" id="SalesOrderLines" style="display:none;">
  <table>
      <tbody id="Content">

      </tbody>
  </table>
</div>
<script type="text/javascript">
    $(function () {
        $(document).on("click", "#SalesOrders tr", function () {
            var $this = $(this); 
            var $SalesOrderLines = $("#SalesOrderLines");
            var id = $this.attr("id");
            $.lajax({
                url: "/SalesOrder/SalesOrderLine",
                params: {"salesOrderId":id},
                callback: function (ret) {
                    var html = [];
                    if (!ret) { return;}
                    var data = ret.Items;
                    if (data.length < 0) { return;}
                    $SalesOrderLines.show();

                    html.push("<tr class='bgc3'>");
                    html.push(" <th>商品编号</th>");
                    html.push(" <th>商品名称</th>");
                    html.push(" <th>规格</th>");
                    html.push(" <th>批号</th>");
                    html.push(" <th>数量</th>");
                    html.push(" <th>单价</th>");
                    html.push(" <th>金额</th>");
                    html.push(" <th>备注</th>");
                    html.push(" <td rowspan='" + (data.length + 2) + "' class='bgc1 bd-top t-c'>");
                    html.push("   <a href='javascript:void(0)' data='" + data[0].SalesOrderId + "' id='SellingOut' class='l-btn submit btn-lg3 btn-hg10'>确认出库</a>");
                    html.push(" </td>");
                    html.push("</tr>");
                    for (var i = 0; i < data.length; i++) {
                        html.push("<tr>");
                        html.push("<td>" + data[i].ProductNo + "</td>");
                        html.push("<td>" + data[i].ProductName + "</td>");
                        html.push("<td>" + data[i].Spec + "</td>");
                        html.push("<td>" + data[i].LotNo + "</td>");
                        html.push("<td>" + data[i].Quantity + "</td>");
                        html.push("<td>" + data[i].Price + "</td>");
                        html.push("<td>" + data[i].Amount + "</td>");
                        html.push("<td class='bd-right'>" + data[i].Remark + "</td>");
                        html.push("</tr>");
                    }
                    $SalesOrderLines.find("tbody#Content").html(html.join(""));
                }
            });
        });
        $(document).on("click", "#SellingOut", function () {
            var id = $(this).attr("data");
            $.lconfirm("是否确定出库", function () {
                $.lajax({
                    url: "/SalesOrder/SellingOut",
                    params: { "salesOrderId": id },
                    callback: function (ret) {
                        if (ret.message) {
                            $.lalert(ret.message);
                        }
                    }
                });
            });
        });
    });
</script>